package com.caogt.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@SpringBootApplication
@EnableDiscoveryClient
@EnableConfigServer
public class ConfigServerStart {
    public static void main(String[] args) {
        SpringApplication.run(ConfigServerStart.class,args);
    }
    @Value("${server.port}")
    private int port;

    @Autowired
    private RestTemplate restTemplate;

    public void refreshConfig(){
        String url = String.format("http://localhost:%s/actuator/bus-refresh",port);
        Map<String,Object> map = new HashMap<>();
        restTemplate.postForObject(url,map,Object.class);
    }
    @Bean
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }
}
